<!--
 * @Author: tkp
 * @Date: 2024-03-29 10:17:43
-->
<template>
  <div>
    <el-form :model="queryForm" label-position="right" :rules="rules" ref="ruleForm" label-width="100px">
      <el-form-item prop="systemId" label="所属系统:">
        <el-radio-group v-model="queryForm.systemId" @input="inputHandle">
          <el-radio v-for="(item) in sysTeamType" :key="item.systemId" :label="item.systemId">{{ item.systemName }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item prop="moduleId" label="系统模块:">
        <Select size="medium" placeholder="请选择系统模块" :clearable="false" v-model="queryForm.moduleId" :data="moduleLst" :jsonType="{'value':'moduleId','label':'moduleName'}"></Select>
      </el-form-item>
      <el-form-item prop="interfaceName" label="接口名称:">
        <Input v-model="queryForm.interfaceName" size="medium" clearable placeholder="请输入接口名称"></Input>
      </el-form-item>
      <el-form-item prop="url" label="URL地址:">
        <Input v-model="queryForm.url" size="medium" clearable placeholder="请输入接口名称"></Input>
      </el-form-item>
      <el-form-item prop="whitelistFlag" label="是否白名单:">
        <el-radio-group v-model="queryForm.whitelistFlag">
          <el-radio :label="0">否</el-radio>
          <el-radio :label="1">是</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="medium" @click="okPop">确认</el-button>
        <el-button size="medium" @click="closePop">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { authModuleQuery, authSystemQuery } from '@/utils/api'
export default {
  data() {
    return {
      queryForm: {
        moduleId: '',
        interfaceName: '',
        url: '',
        whitelistFlag: 0,
        systemId: '',
      },
      moduleLst: [],
      sysTeamType: [],
      rules: {
        systemId: [
          { required: true, message: '此项为必填' },
        ],
        moduleId: [
          { required: true, message: '此项为必填' },
        ],
        interfaceName: [
          { required: true, message: '此项为必填' },
        ],
        url: [
          { required: true, message: '此项为必填' },
        ],
        whitelistFlag: [
          { required: true, message: '此项为必填' },
        ],
      },
    }
  },
  mounted() {
    this.loadSystem()
    this.getModule()
  },
  methods: {
    closePop() {
      this.$emit('addData', '')
    },
    okPop() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.$emit('addData', this.queryForm)
        } else {
          this.messageWarnPop('请填写完整')
          return false;
        }
      });
    },
    inputHandle(e) {
      this.queryForm.moduleId = ''
      this.getModule()
    },
    getModule() {
      let param = {
        pageNum: 1,
        pageSize: 2000,
        systemId: this.queryForm.systemId,
      }
      authModuleQuery(param).then(res => {
        this.moduleLst = res.data
      })
    },
    loadSystem() {
      let param = {
        enable: 1
      }
      authSystemQuery(param).then(res => {
        this.sysTeamType = res.data || []
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.fenrun_class {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 5px;
  .title {
    width: 100px;
  }
  .end {
    color: #999999;
  }
}
/deep/ .el-radio {
  margin-bottom: 10px;
}
</style>
